<style>
    .page li {
        padding: 0;
    }

    .page a,
    .page span {
        display: block;
        width: 1.5em;
        height: 1.5em;
        line-height: 1.5em;
        text-align: center;
        font-size: 1em;
        font-weight: bold;
    }

    .page .active {
        background: #5FB878;
        color: #fff;
    }

    .fly-rank dl {
        text-align: left;
    }
</style>
<div class="fly-panel fly-column">
    <div class="layui-container">
        <!-- 帖子分类 -->
        <ul class="layui-clear">

            <!-- 全部分类名 -->
            <li class="layui-hide-xs {$cateid=='all'?'layui-this':''}">
                <a href="{:url('home/index/index',['cateid'=>'all','state'=>$state])}">全部
                </a>
            </li>

            <!-- 其他分类 -->
            {if condition="$catelist"}
            {foreach $catelist as $item}
            <li class="{$cateid==$item['id'] ? 'layui-this' : ''}">
                <a href="{:url('home/index/index',['cateid'=>$item['id'],'state'=>$state])}">
                    {$item.name}
                </a>
            </li>
            {/foreach}
            {/if}


            <!-- 用户登入后显示 -->
            {if condition="$Think.cookie.LoginUser"}
            <li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block">
                <span class="fly-mid"></span>
            </li>

            <li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block">
                <a href="{:url('home/index/addpost')}">我发表的贴</a>
            </li>

            <li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block">
                <a href="user/index.html#collection">我收藏的贴</a>
            </li>
            {/if}
        </ul>


        <!-- PC端按钮 -->
        <div class="fly-column-right layui-hide-xs">
            <span class="fly-search"><i class="layui-icon"></i></span>
            <a href="{:url('home/post/add')}" class="layui-btn">发表新帖</a>
        </div>

        <!-- 移动端按钮 -->
        <div class="layui-hide-sm layui-show-xs-block"
            style="margin-top: -10px; padding-bottom: 10px; text-align: center;">
            <a href="{:url('home/post/add')}" class="layui-btn">发表新帖</a>
        </div>
    </div>
</div>

<div class="layui-container">
    <div class="layui-row layui-col-space15">

        <!-- 左边 -->
        <div class="layui-col-md8">
            <div class="fly-panel" style="margin-bottom: 0;">
                <!-- 热度 -->
                <div class="fly-panel-title fly-filter">
                    <!-- 全部 -->
                    <a href="{:url('home/index/index',['cateid'=>$cateid,'state'=>'all'])}"
                        class="{$state=='all'?'layui-this':''}">全部</a>
                    <span class="fly-mid"></span>

                    <!-- 置顶 -->
                    <a href="{:url('home/index/index',['cateid'=>$cateid,'state'=>'1'])}"
                        class="{$state=='1'?'layui-this':''}">置顶</a>
                    <span class="fly-mid"></span>

                    <!-- 精华 -->
                    <a href="{:url('home/index/index',['cateid'=>$cateid,'state'=>'2'])}"
                        class="{$state=='2'?'layui-this':''}">精华</a>
                    <span class="fly-mid"></span>

                    <!-- 热门 -->
                    <a href="{:url('home/index/index',['cateid'=>$cateid,'state'=>'3'])}"
                        class="{$state=='3'?'layui-this':''}">热门</a>
                    <span class="fly-mid"></span>

                    <!-- 常规 -->
                    <a href="{:url('home/index/index',['cateid'=>$cateid,'state'=>'0'])}"
                        class="{$state=='0'?'layui-this':''}">常规</a>
                    <span class="fly-filter-right layui-hide-xs">

                        <!-- 采纳和未采纳 -->
                        <a href="{:url('home/index/index',['cateid'=>$cateid,'state'=>$state,'accept'=>''])}"
                            class="{$accept=='' ? 'layui-this' :''}">未采纳</a>
                        <span class="fly-mid"></span>

                        <a href="{:url('home/index/index',['cateid'=>$cateid,'state'=>$state,'accept'=>1])}"
                            class="{$accept==1 ? 'layui-this':''}">已采纳</a>
                    </span>
                </div>

                <!-- 帖子列表 -->
                <ul class="fly-list">
                    {foreach $postlist as $post}
                    <li>
                        <!-- 帖子头像 -->
                        <a href="{:url('home/user/index',['creaid'=>$post['id']])}" class="fly-avatar">
                            {if condition="$post.user.avatar && is_file('.'.$post.user.avatar)"}
                            <img src="{$post.user.avatar}" />
                            {else /}
                            <img src="/assets/home/images/avatar.jpg" />
                            {/if}
                        </a>

                        <!-- 标题分类 -->
                        <h2>
                            {if condition="post.cate.id"}
                            <a class="layui-badge">{$post.cate.name}</a>

                            <a href="{:url('home/index/info',['postid'=>$post['id']])}">{$post.title}</a>
                        </h2>

                        <div class="fly-list-info">
                            <!-- 昵称 -->
                            <a href="javascript:void(0)">
                                <cite>{$post.user.nickname}</cite>
                                <!-- 认证 -->
                                <i class="iconfont icon-renzheng"></i>
                                <!-- VIP -->
                                {if condition="$post.user.vip gt 0"}
                                <i class="layui-badge fly-badge-vip">VIP{$post.user.vip}</i>
                                {/if}

                            </a>

                            <!-- 发帖时间 -->
                            <span>{$post.createtime}</span>

                            <!-- 悬赏积分 -->
                            <span class="fly-list-kiss layui-hide-xs">
                                <i class="iconfont icon-kiss"></i>
                                {$post.point}
                            </span>

                            <!-- 完结状态 -->
                            {if condition="$post.accept"}
                            <span class="layui-badge fly-badge-accept layui-hide-xs">
                                已结
                            </span>
                            {/if}

                            <!-- 评论数 -->
                            <span class="fly-list-nums">
                                <i class="iconfont icon-pinglun1" title="回答"></i>
                                {$post.comment_total}
                            </span>

                        </div>

                        <!-- 热门状态 -->
                        <div class="fly-list-badge">
                            {if condition="$post.state eq 1"}
                            <span class="layui-badge layui-bg-black">置顶</span>
                            {elseif condition="$post.state eq 2"}
                            <span class="layui-badge layui-bg-red">精华</span>
                            {elseif condition="$post.state eq 3"}
                            <span class="layui-badge layui-bg-orange">热门</span>
                            {/if}
                        </div>
                    </li>

                    {/foreach}
                </ul>

                <!-- 分页 -->
                <div class="page">
                    {$postlist->render()}
                </div>
            </div>
        </div>

        <!-- 右边 -->
        <div class="layui-col-md4">
            <!-- 签到 -->
            <div class="fly-panel fly-signin">
                <div class="fly-panel-title">签到</div>

                <div class="fly-panel-main fly-signin-main">
                    <!-- 未签到状态 -->
                    {if condition="$Think.cookie.LoginUser"}
                        {if condition="isset($LoginUser['sign']) && $LoginUser['sign']"}
                        <!-- 已签到状态 -->
                        <button class="layui-btn layui-btn-disabled">今日已签到</button>
                        <span>获得了<cite>{$SignPoint}</cite>积分</span>
                        {else /}
                        <button id="sign" class="layui-btn layui-btn-danger" id="LAY_signin">
                            今日签到
                        </button>
                        <span>可获得<cite>{$SignPoint}</cite>积分</span>
                        {/if}
                    {else /}
                    <button id="sign" class="layui-btn layui-btn-danger" id="LAY_signin">
                        今日签到
                    </button>
                    <span>可获得<cite>{$SignPoint}</cite>积分</span>
                    {/if}

                </div>
            </div>

            <!-- 热门访问 -->
            <div class="fly-panel">
                <h3 class="fly-panel-title">本周热议</h3>
                {if condition="$week"}
                <ul class="fly-panel-main fly-list-static">
                    {foreach $week as $item}
                    <li>
                        <a href="{:url('home/index/info', ['postid' => $item['id']])}" target="_blank">
                            {$item.title}
                        </a>
                    </li>
                    {/foreach}
                </ul>
                {/if}
            </div>

            <!-- 本周热门回帖 -->
            <div class="fly-panel fly-rank fly-rank-reply" id="LAY_replyRank">
                <h3 class="fly-panel-title">回贴周榜</h3>
                {if condition="$userlist"}
                <dl>
                    {foreach $userlist as $item}
                    <dd>
                        <a href="javascript:void(0);">
                            {if condition="$item.avatar AND is_file('.'.$item.avatar)"}
                            <img src="{$item.avatar}">
                            {else /}
                            <img src="/assets/home/images/avatar.jpg">
                            {/if}
                            <cite>{$item.nickname}</cite>
                            <i>{$item.num}次回答</i>
                        </a>
                    </dd>
                    {/foreach}
                </dl>
                {/if}
            </div>

            <!-- 二维码 -->
            <div class="fly-panel" style="padding: 20px 0; text-align: center;">
                <img src="/assets/home/images/weixin.jpg" style="max-width: 100%;" alt="layui">
                <p style="position: relative; color: #666;">微信扫码关注 layui 公众号</p>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'jquery'], function () {
        var $ = layui.jquery

        // 给签到按钮绑定点击事件
        $('#sign').click(function () {
            // 发送ajax请求
            $.ajax({
                url: `{:url('home/index/sign')}`,
                type: 'post',
                dataType: 'json',
                success: function (success) {
                    if (success.code) {
                        //成功
                        layer.msg(
                            success.msg,
                            { icon: 1, time: 1000 },
                            function () {
                                $("#sign").addClass('layui-btn-disabled')
                                $("#sign").text('今日已签到')
                            }
                        )
                    } else {
                        //失败
                        layer.msg(success.msg)
                    }
                }
            })
        })
    })
</script>